Passed
Push — master ( 5b9b93...962dd6 )
by Antonio
01:43
created

spec.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
eloc 18
c 4
b 0
f 0
nc 1
dl 0
loc 7
rs 9.5
nop 0
1
import 'regenerator-runtime/runtime';
2
import '@babel/polyfill';
3
import { expect } from 'chai';
4
import Bawler, { msg } from '../src/index';
5
import messages from './fixtures/lang.js';
6
import remoteMessages from './fixtures/remoteMessages.js';
7
8
/*global describe, it, beforeEach*/
9
10
describe('Bawler', () => {
11
    describe('Configuration', () => {
12
        it('can initialize from a single object', () => {
13
            Bawler.register('en', messages);
14
15
            expect(Bawler.all()).to.deep.equal({ en: messages });
16
        });
17
18
        it('can initialize from an url', async () => {
19
            await Bawler.registerUrl(
20
                'https://gist.githubusercontent.com/mendezcode/8275387/raw/db75e0adae779aaebfe25cd0e953356e34fc8d03/locales.json',
21
                'test'
22
            );
23
24
            expect(Bawler.all('test')).to.deep.equal(remoteMessages);
25
        });
26
27
        it('can change language', async () => {
28
            Bawler.lang('zu');
29
            expect(Bawler.currentLang).to.equal('zu');
30
        });
31
    });
32
33
    describe('Messages', () => {
34
        beforeEach(() => {
35
            Bawler.lang();
36
            Bawler.messages = {};
37
        });
38
39
        it('returns empty object when the language does not have any message', () => {
40
            expect(Bawler.all('foo')).to.be.empty;
41
        });
42
43
        it('can get messages from a single language', () => {
44
            Bawler.register('en', messages);
45
46
            expect(Bawler.all('en')).to.deep.equal(messages);
47
        });
48
49
        it('can output messages that are not registered', () => {
50
            expect(Bawler.msg('TEST')).to.equal('TEST');
51
        });
52
53
        it('can replace variables in messages', () => {
54
            expect(Bawler.msg('HELLO %s', ['Foo'])).to.equal('HELLO Foo');
55
        });
56
57
        it('outputs registered messages', () => {
58
            Bawler.register('en', { Foo: 'bar' });
59
60
            expect(Bawler.msg('Foo')).to.equal('bar');
61
        });
62
63
        it('outputs messages in different languages', () => {
64
            Bawler.register('en', { HELLO: 'hello' });
65
            Bawler.register('es', { HELLO: 'hola' });
66
67
            Bawler.lang('en');
68
            expect(Bawler.msg('HELLO')).to.equal('hello');
69
70
            Bawler.lang('es');
71
            expect(Bawler.msg('HELLO')).to.equal('hola');
72
        });
73
74
        it('outputs messages with shortcut function', () => {
75
            expect(msg('HELLO WORLD')).to.equal('HELLO WORLD');
76
        });
77
    });
78
});
79